<template>
  <div class="pointmanagement">
    <basic-container>
      <avue-crud :option="option"
                 :table-loading="loading"
                 :data="data"
                 :page.sync="page"
                 :permission="permissionList"
                 :before-open="beforeOpen"
                 v-model="form"
                 ref="crud"
                 @row-update="rowUpdate"
                 @row-save="rowSave"
                 @row-del="rowDel"
                 @search-change="searchChange"
                 @search-reset="searchReset"
                 @selection-change="selectionChange"
                 @current-change="currentChange"
                 @size-change="sizeChange"
                 @refresh-change="refreshChange"
                 @on-load="onLoad">
        <template slot="menuLeft">
          <el-button type="danger"
                     size="small"
                     icon="el-icon-delete"
                     plain
                     v-if="permission.pointmanagement_delete"
                     @click="handleDelete">删 除
          </el-button>
        </template>
        <!-- 现场图片表单自定义 -->
        <template slot="xczpForm">
          <div v-if="dialogType !== 'view'">
            <el-button
              size="small"
              type="primary"
              @click="uploadXCZP">
              上传图片
            </el-button>
            <span style="margin-left: 10px; color: #606266; font-size: 12px;">只能上传图片，最多选择3张</span>
            <input
              accept="image/*"
              ref="xczpUpload"
              id="xczpUpload"
              style="display: none;"
              type="file"
              @change="xczpUpload"
              multiple />
          </div>
        </template>

        <!-- 现场照片内容表单自定义 -->
        <template slot="xczpContentForm">
          <div class="xczp_content">
            <el-tag
              v-for="(item, index) in xczpFileList"
              :key="index"
              type="info"
              :closable="dialogType !== 'view'"
              @close="handleRemoveXCZP(index)"
            >
              <img
                :src="item.response.data.fileUrl"
                @click="previewXCZP(item)"
                alt />
            </el-tag>
          </div>
        </template>

        <!-- 现场照片表格自定义 -->
        <template slot="xczp" slot-scope="scope">
          <div class="ope_row_div">
            <span v-if="scope.row['xczp'] === '' || scope.row['bladeFiles'].length === 0">-</span>
            <el-button v-else type="text" @click="handleViewPhoto(scope.row)">查看</el-button>
          </div>
        </template>
        <!-- 历史巡检记录 -->
        <template slot="lsxjjl" slot-scope="scope">
          <el-form label-width="0px">
            <el-button type="danger" size="mini" @click="handleJl(scope.row['rwmc'])">查看记录</el-button>
          </el-form>
        </template>
        <!-- 状态表格自定义 -->
        <template slot="status" slot-scope="scope">
          <span>{{formatStatus(scope.row)}}</span>
        </template>
        <!-- 核实人表格自定义 -->
        <template slot="hssz" slot-scope="scope">
          <div>
            <el-button v-if="scope.row['zt'] === 1" type="warning" size="mini" @click="handleVerifier(scope.row)">添加核实人</el-button>
            <span v-else>-</span>
          </div>
        </template>
        <!-- 情况核实表格自定义 -->
        <template slot="qkhs" slot-scope="scope">
          <div>
            <el-button v-if="scope.row['zt'] === 2" type="success" size="mini" @click="handleVerify(scope.row)">核 实</el-button>
            <span v-else>-</span>
          </div>
        </template>

      </avue-crud>
      <!-- 弹窗：图片 -->
      <viewpicture
        :localPicBox="localPicBox"
        :localPictures="localPictures"
        @confirmViewPicture="confirmViewPicture"
        @handleClosePicBox="handleClosePicBox">
      </viewpicture>
      <!-- 历史记录弹窗 -->
      <el-dialog
        title="巡检历史记录"
        append-to-body
        :visible.sync="historyRecordDialog"
        :close-on-click-modal="false"
        :before-close="closeHistoryRecordDialog"
        width="60%"
        class="history_record_dialog"
      >

        <!-- 历史巡检表格内容 -->
        <avue-crud
          :option="historyRecordOption"
          :table-loading="historyRecordLoading"
          :data="historyRecordData"
          :page.sync="historyRecordPage"
          v-model="historyRecordForm"
        >
        </avue-crud>
        <!-- 按钮 -->
        <div class="modify_record_footer">
          <el-button
            type="primary"
            size="small"
            @click="closeHistoryRecordDialog()">
            确 定
          </el-button>
        </div>
      </el-dialog>

      <!-- 弹窗：添加核实人 -->
      <el-dialog
        title="添加核实人"
        append-to-body
        :visible.sync="verifierDialog"
        :close-on-click-modal="false"
        :before-close="closeVerifierDialog"
        width="60%"
        class="add_violation_dialog"
      >
        <avue-form
          ref="updateForm"
          v-model="updateObj"
          :option="updateOption"
          @submit="confirmVerifier"
        >
          <template slot="menuForm">
            <el-button
              size="small"
              icon="el-icon-close"
              @click="closeVerifierDialog()">
              取 消
            </el-button>
          </template>
        </avue-form>
      </el-dialog>
      <!-- 弹窗：核实情况 -->
      <el-dialog
        title="添加核实情况"
        append-to-body
        :visible.sync="verifyDialog"
        :close-on-click-modal="false"
        :before-close="closeVerifyDialog"
        width="60%"
        class="add_violation_dialog"
      >
        <avue-form
          ref="updateForm1"
          v-model="updateObj1"
          :option="updateOption1"
          @submit="confirmVerifyRelatedParty"
        >
          <template slot="menuForm">
            <el-button
              size="small"
              icon="el-icon-close"
              @click="closeVerifyDialog()">
              取 消
            </el-button>
          </template>
        </avue-form>
      </el-dialog>
    </basic-container>
  </div>
</template>

<script>
  import {getList, getDetail, add, update, remove,getPointmanagementStatus,getHistoryRecordList} from "@/api/xjgl/pointmanagement";
  import {mapGetters} from "vuex";
  import {removePic, uploadFiles} from "@/api/mmhi/prod_plant";
  import viewpicture from "@/views/saferisk/components/viewpicture";

  export default {
    components:{
      viewpicture,
    },
    data() {
      return {
        form: {},
        query: {},
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        localPicUrl: "",
        localPicBox: false,
        //照片上传设置
        xczpFileList: [],
        dialogType:'',
        localPictures: [],
        photoBox: false,
        attachBox: false,
        selectionList: [],
        option: {
          height:'auto',
          calcHeight: 30,
          tip: false,
          searchShow: true,
          searchMenuSpan: 6,
          border: true,
          index: true,
          viewBtn: true,
          selection: true,
          dialogClickModal: false,
          column: [
            {
              label: "巡检点名称",
              prop: "rwmc",
              align: "center",
              width:90,
              search: true,
              rules: [{
                required: true,
                message: "请输入巡检点名称（取自自定义巡检点的点位名称）",
                trigger: "blur"
              }]
            },
            {
              label: "巡检人",
              prop: "xjr",
              align: "center",
              width:"60px",
              search: true,
              rules: [{
                required: true,
                message: "请输入巡检人",
                trigger: "blur"
              }]
            },
            {
              label: "所在岗位",
              prop: "szgw",
              align: "center",
              hide:true,
              rules: [{
                required: true,
                message: "请输入所在岗位",
                trigger: "blur"
              }]
            },
            {
              label: "所在部门",
              prop: "szbm",
              width:90,
              align: "center",
              rules: [{
                required: true,
                message: "请输入所在部门",
                trigger: "blur"
              }]
            },
            {
              label: "检查频次",
              prop: "jcpc",
              align: "center",
              width:70,
              rules: [{
                required: true,
                message: "请输入检查频次",
                trigger: "blur"
              }]
            },
            {
              label: "巡检生产区域",
              prop: "xjscqy",
              align: "center",
              width:110,
              rules: [{
                required: true,
                message: "请输入巡检生产区域",
                trigger: "blur"
              }]
            },
            {
              label: "巡检设备设施",
              prop: "xjsbss",
              align: "center",
              hide:true,
              rules: [{
                required: true,
                message: "请输入巡检设备设施",
                trigger: "blur"
              }]
            },
            {
              label: "巡检点位ID",
              prop: "xjdwid",
              align: "center",
              hide: true,
              rules: [{
                required: true,
                message: "请输入巡检点位ID",
                trigger: "blur"
              }]
            },
            {
              label: "巡检时间",
              prop: "xjsj",
              align: "center",
              width:140,
              type: "datetime",
              format: "yyyy-MM-dd HH:mm:ss",
              valueFormat: "yyyy-MM-dd HH:mm:ss",
              rules: [{
                required: true,
                message: "请输入巡检时间",
                trigger: "blur"
              }]
            },
            {
              label: "巡检标准",
              prop: "xjbz",
              align: "center",
              hide: true,
              rules: [{
                required: true,
                message: "请输入巡检标准",
                trigger: "blur"
              }]
            },
            {
              label: "巡检隐患描述",
              prop: "xjyhms",
              align: "center",
              width:140,
              rules: [{
                required: true,
                message: "请输入巡检隐患描述",
                trigger: "blur"
              }]
            },
            {
              label: "巡检隐患照片",
              prop: "xczp",
              align: "center",
              slot: true,
              span: 24,
              width: 100,
              formslot:true,
            },
            {
              label: "",
              prop: "xczpContent",
              hide: true,
              span: 24,
              formslot: true
            },
            {
              label: "巡检结果",
              prop: "xjjg",
              align: "center",
              width:"80px",
              type: "select",
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=patrol_point_management_xjjg",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              //addDisplay: false,
              dataType:"number",
              editDisplay: false,
              hide: false,
            },
            {
              label: "状态",
              display: false,
              prop: "status",
              align: "center",
              width: 130,
              slot: true
            },
            {
              label: "核实人",
              prop: "hsr",
              align: "center",
              dicUrl: "/api/emerRectify/rectify/getPersonInfo",
              props: {
                label: "name",
                value: "id",
              },
              width:"60px",
              addDisplay: false,
              editDisplay: false,
              hide: false,
            },
            {
              label: "核实时间",
              prop: "hssj",
              align: "center",
              addDisplay: false,
              editDisplay: false,
              hide: true,
            },
            {
              label: "巡检隐患级别",
              prop: "xjyhjb",
              width: 100,
              search: true,
              type: "select",
              align: "center",
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=patrol_point_management_xjyhjb",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              addDisplay: false,
              editDisplay: false,
              dataType:"number"
            },
            {
              label: "核实结果",
              prop: "hsjg",
              align: "center",
              addDisplay: false,
              editDisplay: false,
              hide: true,
            },
            {
              label: "历史巡检记录",
              prop: "lsxjjl",
              align: "center",
              width:100,
              slot: true,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              hide: false,
            },
            {
              label: "核实设置",
              prop: "hssz",
              align: "center",
              width:110,
              slot: true,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              hide: false,
            },
            {
              label: "情况核实",
              prop: "qkhs",
              width:80,
              align: "center",
              slot: true,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              hide: false,
            },
            {
              label: "备注",
              prop: "bz",
              align: "center",
              width:"600px",
              type: "textarea",
              maxlength:500,
              span: 24,
              minRows: 6,
              hide: true,
              rules: [{
                required: false,
                message: "请输入备注",
                trigger: "blur"
              }]
            },
            {
              label: "企业id",
              prop: "bladeDeptId",
              hide: true,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false
            },
            {
              label: "租户id",
              prop: "tenantId",
              hide: true,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false
            },
            {
              label: "创建人",
              prop: "createUser",
              hide: true,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false
            },
            {
              label: "创建部门",
              prop: "createDept",
              hide: true,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false
            },
            {
              label: "创建时间",
              prop: "createTime",
              hide: true,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false
            },
          ]
        },
        data: [],
        //表格状态列
        statusObj: {},
        // 查看历史记录弹窗
        historyRecordDialog: false,
        rwmcHistory: "",
        historyRecordForm: {},
        historyRecordLoading: true,
        historyRecordQuery: {},
        historyRecordData: [],
        historyRecordPage: {
          pageSize: this.$pageSize,
          currentPage: 1,
          total: 0
        },
        historyRecordOption: {
          searchShow: true,
          searchMenuSpan: 6,
          border: true,
          viewBtn: true,
          dialogClickModal: false,
          calcHeight: 30,
          tip: false,
          index: true,
          selection: false,
          addBtn: false,
          refreshBtn: false,
          columnBtn: false,
          menu: false,
          column: [
            {
              label: "巡检点名称",
              prop: "rwmc",
              align: "center",
              width:"100px",
            },
            {
              label: "巡检人",
              prop: "xjr",
              align: "center",
              width:"60px",
            },
            {
              label: "所在部门",
              prop: "szbm",
              align: "center",
              width:"90px",
            },
            {
              label: "检查频次",
              prop: "jcpc",
              align: "center",
              width:"80px",
            },
            {
              label: "巡检生产区域",
              prop: "xjscqy",
              align: "center",
              width:"100px",
            },
            {
              label: "巡检设备设施",
              prop: "xjsbss",
              align: "center",
              width:"100px",
            },
            {
              label: "巡检时间",
              prop: "xjsj",
              align: "center",
              width:140,
              type: "datetime",
              format: "yyyy-MM-dd HH:mm:ss",
              valueFormat: "yyyy-MM-dd HH:mm:ss",
            },
            {
              label: "巡检隐患描述",
              prop: "xjyhms",
              align: "center",
              width:140,
            },
            // {
            //   label: "巡检隐患照片",
            //   prop: "xczp",
            //   align: "center",
            //   slot: true,
            //   span: 24,
            //   width: 100,
            //   formslot:true,
            // },
            // {
            //   label: "",
            //   prop: "xczpContent",
            //   hide: true,
            //   span: 24,
            //   formslot: true
            // },
            {
              label: "巡检结果",
              prop: "xjjg",
              align: "center",
              width:"80px",
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=patrol_point_management_xjjg",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              dataType:"number",
            },
            {
              label: "状态",
              display: false,
              prop: "zt",
              width: 130,
              align: "center",
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=patrol_point_management_zt",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              dataType:"number",
            },
            {
              label: "核实人",
              prop: "hsr",
              align: "center",
              dicUrl: "/api/emerRectify/rectify/getPersonInfo",
              props: {
                label: "name",
                value: "id",
              },
              width:"60px",
            },
            {
              label: "巡检隐患级别",
              prop: "xjyhjb",
              align: "center",
              width:"120px",
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=patrol_point_management_xjyhjb",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              addDisplay: false,
              dataType:"number"
            },

          ]
        },
        // 弹窗：审批设置
        verifierDialog: false,
        selectedSettingId:{},
        updateObj:{},
        // 弹窗：审批
        verifyDialog: false,
        verifyPartyId:{},
        updateObj1:{},
      };
    },
    computed: {
      ...mapGetters(["permission"]),

      updateOption() {
        return {
          size: "small",
          submitText: "确 定",
          labelWidth: 110,
          mockBtn: false,
          printBtn: false,
          emptyBtn: false,
          column: [
            {
              label: "核实人",
              prop: "hsr",
              span: 12,
              type: "select",
              dicUrl: "/api/emerRectify/rectify/getPersonInfo",
              props: {
                label: "name",
                value: "id",
              },
              rules: [{
                required: true,
                message: "请输入核实人",
                trigger: "blur"
              }]
            },

          ]
        }
      },

      updateOption1() {
        return {
          size: "small",
          submitText: "确 定",
          labelWidth: 110,
          mockBtn: false,
          printBtn: false,
          emptyBtn: false,
          column: [
            {
              label: "巡检隐患级别",
              prop: "xjyhjb",
              span: 12,
              type: "select",
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=patrol_content_library_xjjb",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: true,
                message: "巡检隐患级别",
                trigger: "blur"
              }]
            },
            {
              label: "核实时间",
              prop: "hssj",
              span: 12,
              type: "datetime",
              format: "yyyy-MM-dd HH:mm:ss",
              valueFormat: "yyyy-MM-dd HH:mm:ss",
              rules: [{
                required: true,
                message: "请选择核实时间",
                trigger: "change"
              }]
            },
            {
              label: "核实结果",
              prop: "hsjg",
              span: 24,
              type: "textarea",
              maxlength: 150,
              rules: [{
                required: true,
                message: "请输入违规内容",
                trigger: "blur"
              }]
            },
          ]
        }
      },

      permissionList() {
        return {
          addBtn: this.vaildData(this.permission.pointmanagement_add, false),
          viewBtn: this.vaildData(this.permission.pointmanagement_view, false),
          delBtn: this.vaildData(this.permission.pointmanagement_delete, false),
          editBtn: this.vaildData(this.permission.pointmanagement_edit, false)
        };
      },
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      },
      player () {
        return this. $refs. videoPlayer. player
      },
      //现场照片id
      picIds() {
        let picIds = [];
        this.selectionList.forEach(ele => {
          picIds.push(ele.xczp);
        });
        return picIds.join(",");
      }
    },
    mounted() {
      this.initData();
    },
    methods: {
      initData() {
        getPointmanagementStatus().then(res => {
            this.statusObj = {};
            res.data.data.forEach(item => {
              this.statusObj[item.dictKey] = item.dictValue;
            });
          })
      },
      /**
       * 上传现场照片
       */
      xczpUpload(element) {
        console.log(element);
        if(this.$refs.xczpUpload.files.length + this.xczpFileList.length > 3) {
          this.$message.warning("最多上传3张现场图片!");
          this.$refs.xczpUpload.value = null;
          return;
        }
        let formData = {};
        let files = this.$refs.xczpUpload.files;
        formData = new FormData();
        for(let i = 0 ; i < files.length ; i++) {
          formData.append("files", files[i]);
        }
        uploadFiles(formData).then(res => {
          if(!res.data.success) {
            return;
          }
          var resData = res.data.data;
          resData.forEach(item => {
            this.xczpFileList.push({
              name: item.fileName,
              response: {
                code: 200,
                msg: "操作成功",
                success: true,
                data: item
              }
            });
          });
          this.$refs.xczpUpload.value = null;
        });
      },
      // 点击上传图片按钮
      uploadXCZP() {
        document.getElementById("xczpUpload").click();
      },
      // 获取现场照片ids
      formatPictureIds(filelist) {
        var ids = [];
        filelist.forEach(item => {
          ids.push(item.response.data.id);
        });
        return ids.join(",");
      },
      // 删除现场照片
      handleRemoveXCZP(index) {
        this.xczpFileList.splice(index, 1);
      },

      /**
       * 弹窗：图片
       */
      // 查看现场照片
      handleViewPhoto(row) {
        this.localPictures = row.bladeFiles;
        this.localPicBox = true;
      },

      // 点击图片列表中已上传的现场图片
      previewXCZP(file) {
        if(file.response && file.response.code === 200 && file.response.data && file.response.data.fileUrl) {
          this.localPictures = [file.response.data];
          this.localPicBox = true;
        }
      },
      // 确认照片
      confirmViewPicture() {
        this.localPictures = [];
        this.localPicBox = false;
      },

      // 关闭弹窗
      handleClosePicBox() {
        this.confirmViewPicture();
      },

      // 上传现场图片前
      beforeUploadXCZP(file) {
        var isLt2M = file.size / 1024 / 1024 < 2;
        var isLimit = (this.xczpFileList.length + 1) <= 3 ;
        if (!isLt2M) {
          this.$message.warning('图片大小不能超过2MB!');
        }
        if (!isLimit) {
          this.$message.warning('最多上传3张现场图片!');
        }
        return isLt2M && isLimit;
      },

      // 上传现场图片成功
      uploadXCZPSuccess(response, file, fileList) {
        if(response.code !== 200 || response.success !== true) {
          return;
        }
        this.xczpFileList = [];
        fileList.forEach(item => {
          this.xczpFileList.push({
            name: item.name,
            response: {
              code: 200,
              data: Array.isArray(item.response.data) === true ? item.response.data[0] : item.response.data,
              msg: "操作成功",
              success: true
            }
          });
        });
      },


      // 格式化状态列
      formatStatus(row) {
        return this.statusObj[row.zt];
      },

      // 打开历史记录记录弹窗
      handleJl(row) {
        this.rwmcHistory ='';
        this.rwmcHistory = row;
        this.historyRecordDialog = true;
        this.historyRecordPage.currentPage = 1;
        this.historyRecordOnLoad(this.historyRecordPage);
      },

      // 获取历史记录记录列表
      historyRecordOnLoad(page, params = {}) {
        this.historyRecordLoading = true;
        params.rwmcHistory=this.rwmcHistory
        getHistoryRecordList(page.currentPage, page.pageSize, Object.assign(params, this.historyRecordQuery)).then(res => {
          let resData = res.data.data;
          this.historyRecordPage.total = resData.total;
          this.historyRecordData = resData.records;
          this.historyRecordLoading = false;

        });
      },

      // 确认、取消、关闭历史记录记录弹窗
      closeHistoryRecordDialog() {
        this.historyRecordDialog = false;
        this.rwmcHistory = "";
      },

      /**
       * 弹窗：添加核实人员
       */

      // 打开人员信息弹窗
      handleVerifier(row) {
        this.selectedSettingId = row;
        this.updateObj = this.formatUpdateObj(row);
        this.verifierDialog = true;
      },

      // 格式化审批设置数据
      formatUpdateObj() {
        var data = {
          hsr: "",
        };
        return data;
      },

      // 确定人员
      confirmVerifier() {
        this.$refs.updateForm.validate((vaild,done)=>{
          if(vaild){
            this.selectedSettingId.zt = 2;
            this.selectedSettingId.hsr= this.updateObj.hsr
            update(this.selectedSettingId).then(res => {
              if(res.data.success) {
                this.closeVerifierDialog();
                this.page.currentPage = 1;
                this.onLoad(this.page);
                this.$message({
                  type: "success",
                  message: "操作成功!"
                });
              }
            });
            done();
          }
        })
      },

      // 关闭、取消审批设置弹窗
      closeVerifierDialog() {
        this.selectedSettingId = {};
        this.verifierDialog = false;
      },

      /**
       * 弹窗：情况核实
       */

      // 打开核实弹窗
      handleVerify(row) {
        this.verifyPartyId = row;
        this.updateObj1 = this.formatUpdateObj1(row);
        this.verifyDialog = true;
      },

      // 格式化情况核实数据
      formatUpdateObj1() {
        var data = {
          xjyhjb: "",
          hssj: "",
          hsjg: "",
        };
        return data;
      },

      // 关闭、取消情况核实弹窗
      closeVerifyDialog() {
        this.verifyPartyId = {};
        this.verifyDialog = false;
      },

      // 确认添加核实信息
      confirmVerifyRelatedParty() {
        this.$refs.updateForm1.validate((vaild,done)=>{
          if(vaild){
            this.verifyPartyId.zt = 3 ;
            this.verifyPartyId.xjyhjb = this.updateObj1.xjyhjb
              this.verifyPartyId.hssj= this.updateObj1.hssj
              this.verifyPartyId.hsjg= this.updateObj1.hsjg
            update(this.verifyPartyId).then(res => {
              if(res.data.success) {
                this.closeVerifyDialog();
                this.page.currentPage = 1;
                this.onLoad(this.page);
                this.$message({
                  type: "success",
                  message: "操作成功!"
                });
              }
            });
            done();
          }
        })
      },

      rowSave(row, done, loading) {
        row.xczp = this.xczpFileList.length === 0 ? "" : this.formatPictureIds(this.xczpFileList);
        add(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          loading();
          window.console.log(error);
        });
      },
      rowUpdate(row, index, done, loading) {
        row.xczp=this.xczpFileList.length==0?"":this.formatPictureIds(this.xczpFileList)
        update(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          loading();
          console.log(error);
        });
      },
      rowDel(row) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            if (row.xczp!="") {
              removePic(row.xczp)
            }
            return remove(row.id);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
          });
      },
      handleDelete() {
        if (this.selectionList.length === 0) {
          this.$message.warning("请选择至少一条数据");
          return;
        }
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            this.picIds.split(",").forEach(picId=>{
              if (picId!=="") {
                removePic(picId);
              }
            })
            return remove(this.ids);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$refs.crud.toggleSelection();
          });
      },
      beforeOpen(done, type) {
        switch(type) {
          case 'add':
            this.dialogType =''
            this.xczpFileList = [];

            done();
            break
          case 'edit':
            this.dialogType =''
            this.xczpFileList = [];
            this.form.bladeFiles.forEach(item => {
              this.xczpFileList.push({
                name: item.fileName,
                response: {
                  code: 200,
                  data: item,
                  msg: "操作成功",
                  success: true
                }
              });
            });
            getDetail(this.form.id).then(res => {
              this.form = res.data.data;
            });
            done();
            break
          case 'view':
            this.xczpFileList = [];
            this.form.bladeFiles.forEach(item => {
              this.xczpFileList.push({
                name: item.fileName,
                response: {
                  code: 200,
                  data: item,
                  msg: "操作成功",
                  success: true
                }
              });
            });
            this.dialogType = type;
            done();
            break
          default:
            break
        }
      },
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done();
      },
      selectionChange(list) {
        this.selectionList = list;
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
      currentChange(currentPage){
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize){
        this.page.pageSize = pageSize;
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
      },
      onLoad(page, params = {}) {
        this.loading = true;
        getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
        });
      }
    }
  };
</script>
<style lang="scss" >
  .pointmanagement {
    .el-form-item__label {
      width: 100px !important;
    }

    .avue-form__row {
      .el-form-item__content {
        margin-left: 100px !important;
      }
    }
  }
  .add_violation_dialog {
    .avue-form__menu--center {
      text-align: center !important;
      margin-bottom: 0px;
    }
  }
  .modify_record_footer {
    text-align: center;
    margin-top: 15px;

    .el-button {
      width: 100px;
      height: 35px;
    }
  }
</style>
<style lang="scss" scoped>
  .xczp_content {
    width: 100%;
    height: 118px;
    line-height: 105px;
    border: 1px solid #DCDFE6;
    border-radius: 4px;

  .el-tag {
    height: 100px;
    line-height: 100px;
    padding: 0px 10px 0px 0px;
    margin-left: 10px;
    margin-top: 10px;

  .el-icon-close {
    top: -84px;
  }
  }

  img {
    width: 98px;
    height: 98px;
    cursor: pointer;
  }
  }

  .ope_row_div {
  .el-button {
    font-size: 12px;
  }
  }

  .el-carousel {
  .el-carousel__container {
    height: 500px;
    text-align: center;

  img {
    height: 100%;
  }
  }
  }
</style>
